package com.yunhe.transfer.client;

import com.yunhe.transfer.client.fallback.MeasRealtimeFallbackFactory;
import com.yunhe.common.model.DomainList;
import com.yunhe.common.model.ResultObject;
import com.yunhe.common.model.data.Measurement;
import com.yunhe.common.model.data.MeasurementReqDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Map;

@ApiIgnore
@FeignClient(value = "yh-meas-realtime", fallbackFactory = MeasRealtimeFallbackFactory.class)
@RequestMapping(value = "/measurements/realtime")
@Component
public interface MeasRealtimeClient {

    @RequestMapping(value = "/batch", method = RequestMethod.POST)
    void save(@RequestBody Map<Long, Double> map);

    @RequestMapping(value = "/object/batch", method = RequestMethod.POST)
    void saveObj(@RequestBody DomainList<Measurement> domainList);

    @RequestMapping(value = "/object", method = RequestMethod.POST)
    ResponseEntity<ResultObject<Object>> saveOneObj(@RequestBody Measurement measurement);

    @RequestMapping(value = "/object", method = RequestMethod.GET)
    ResponseEntity<ResultObject<Map<Long, Measurement>>> getValue(@RequestParam("pointNumber") Long pointNumber);

    @RequestMapping(value = "/batchGet", method = RequestMethod.POST)
    ResponseEntity<ResultObject<Map<Long, Double>>> getMeasureRealtime(@RequestBody MeasurementReqDTO map);

    /**
     * 清空量测实时备份
     * @param map 点号列表
     */
    @RequestMapping(value = "/clearBackup", method = RequestMethod.POST)
    ResponseEntity<ResultObject> clearBackup(@RequestBody MeasurementReqDTO map);

    /**
     * 将量测实时对象转为备份
     * @param map 点号列表
     */
    @RequestMapping(value = "/movetoBackup", method = RequestMethod.POST)
    ResponseEntity<ResultObject> movetoBackup(@RequestBody MeasurementReqDTO map);

    /**
     * 将量测实时对象转为备份
     * @param map 点号列表
     */
    @RequestMapping(value = "/getBackup", method = RequestMethod.POST)
    ResponseEntity<ResultObject<Map<Long, Double>>> getBackup(@RequestBody MeasurementReqDTO map);

    /**
     * 更新量测实时对象
     * @param pointNumber 点号
     * @param rtime 时间戳
     * @param val 值
     */
    @RequestMapping(method = RequestMethod.PUT)
    ResponseEntity<ResultObject> updateMeasureRealtime(@RequestParam("pointNumber") Long pointNumber,
                                                       @RequestParam("rtime") Long rtime,
                                                       @RequestParam("dtime") String dtime,
                                                       @RequestParam("val") Double val);
}
